Repository navigation
Conversation
Lossless (VP8L) and lossy (VP8) decoding with alpha and animation, following RFC 9649 and RFC 6386. The output is bit-exact with libwebp: all 96 test vectors of libwebp-test-data match their reference checksums (the color conversion and chroma upsampling reproduce libwebp's). A lossless encoder (palette or subtract green + predictor, LZ77 with the short 2D distance codes, color cache) writes files about 25% smaller than our PNGs, and libwebp decodes them identically. Animation gains encodeWebP() and Animation.decode() reads animated WebPs; Image.decode() reads still ones, Image.encodeWebP() writes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ljnxm1Qjrocq1izGajLx8J
The short distance code table is taken from the RFC, whose code components come under the Revised BSD License: the notice is in the vp8l.ts header and THIRD_PARTY_NOTICES.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ljnxm1Qjrocq1izGajLx8J
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds WebP decoding (lossy, lossless, alpha, animated) and lossless WebP encoding, all in plain TypeScript.
Decoding
Image.decode(), including the Exif orientation like the other formats.Animation.decode()composites the frames the way libwebp's animation decoder does.Image.decode()refuses them with a pointer toAnimation.decode(), anddecode()returns them asAnimation.ImageType.isWebP(), andImageType.getType()returns'webp'.Encoding (lossless)
Image.encodeWebP(): files are about 25% smaller than our PNGs at compression level 6.Animation.encodeWebP(): writes animated WebPs.Verification
libwebp-test-datathat have reference checksums decode bit-exactly to dwebp's output. That covers lossy, lossless, alpha, segmentation, both loop filters and all transforms.bad_palette_index.webp) matches libwebp's reference checksum, Pillow handles the invalid index differently.tests/webp.js, with fixtures written by libwebp and checksums of libwebp's decoded pixels.Credits
The VP8 constant tables are extracted from RFC 6386. The YUV→RGB conversion, the "fancy" chroma upsampling and the blending of animation frames reproduce libwebp's integer arithmetic, so the output matches libwebp exactly. Both are BSD-licensed and credited in
THIRD_PARTY_NOTICES.mdand the source headers.The WebP container and the lossless codec follow RFC 9649, whose short distance code table is included under the Revised BSD License.
Package size grows from ~112 kB to ~140 kB (compressed).
Closes #19
Closes #20